home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4486 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  37 lines

  1. Newsgroups: comp.lang.c,comp.lang.c++,gnu.gcc.help,gnu.g++.help,comp.os.msdos.djgpp
  2. Path: cwi.nl!dik
  3. From: dik@cwi.nl (Dik T. Winter)
  4. Subject: Re: float != float and floats as return types
  5. Message-ID: <DM04ur.I6u@cwi.nl>
  6. Sender: news@cwi.nl (The Daily Dross)
  7. Nntp-Posting-Host: chrysant.cwi.nl
  8. Organization: CWI, Amsterdam
  9. References: <4ej9lb$mpc@fu-berlin.de>
  10. Date: Tue, 30 Jan 1996 16:08:50 GMT
  11.  
  12. In article <4ej9lb$mpc@fu-berlin.de> axl@zedat.fu-berlin.de writes:
  13.  > Hello,
  14.  > I am getting confused, about how C/C++ manage float binary operations,
  15.  > in particular multiplication. The next C++ example gives me surprising
  16.  > results:
  17. ...
  18.  >     float quad( float );
  19. ...
  20.  >         a = i/13.123123;
  21.  >         b = a*a;
  22.  >         c = quad(a);
  23.  >         cout << (b - c) << '\t';
  24.  >         cout << (b - a*a) << '\t';
  25.  >         cout << (c - quad(a)) << '\n';
  26.  
  27. Declaring a function as returning float does not imply that the actual
  28. value returned is indeed a float!  In K&R times expressions involving
  29. floats were calculated using doubles.  Some compilers extended that
  30. to functions declared as returning float: a double result was returned;
  31. others did indeed truncate the return value to float.  Thorough
  32. reading of K&R does not lead to a clear solution here.  In ANSI C both
  33. are allowed.
  34. -- 
  35. dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland, +31205924098
  36. home: bovenover 215, 1025 jn  amsterdam, nederland; http://www.cwi.nl/~dik/
  37.